// 模拟后端动态生成路由
import { defineFakeRoute } from "vite-plugin-fake-server/client";
import { customer, product, groupcall, structure, system, customerData, team, groupcallTask, script } from '@/router/enums';

/**
 * roles：页面级别权限，这里模拟二种 "admin"、"common"
 * admin：管理员角色
 * common：普通角色
 */

// 客户管理
const customerManagementRouter = {
  path: "/customerManagement",
  meta: {
    icon: "ri:user-3-line",
    title: "客户管理",
    rank: customer
  },
  children: [
    {
      path: "/customerManagement/data/index",
      name: "customerManagementData",
      meta: {
        icon: "ri:database-2-line",
        title: "客户数据",
        roles: ["admin"]
      },
    },
    {
      path: "/customerManagement/label/index",
      name: "customerManagementLabel",
      meta: {
        icon: "ri:price-tag-3-line",
        title: "标签管理",
        roles: ["admin"]
      }
    },
    {
      path: "/customerManagement/rules/index",
      name: "customerManagementRules",
      meta: {
        icon: "ri:settings-3-line",
        title: "数据处理规则",
        roles: ["admin"]
      }
    },
    {
      path: "/customerManagement/highseas/index",
      name: "customerManagementHighseas",
      meta: {
        icon: "ri:archive-line",
        title: "客户公海",
        roles: ["custom"]
      }
    },
    {
      path: "/customerManagement/myclient/index",
      name: "customerManagementMyclient",
      meta: {
        icon: "ri:star-line",
        title: "我的客户",
        roles: ["custom"]
      }
    },
  ]
}

// 产品管理
const productManagementRouter = {
  path: "/productManagement",
  meta: {
    icon: "ri:box-3-line",
    title: "成交产品管理",
    rank: product
  },
  children: [
    {
      path: "/productManagement/index",
      name: "productManagement",
      meta: {
        title: "成交产品管理",
        roles: ["admin"]
      }
    }
  ]
}

// 群呼管理
const groupcallManagementRouter = {
  path: "/groupcallManagement",
  meta: {
    icon: "ri:calculator-line",
    title: "群呼管理",
    rank: groupcall
  },
  children: [
    {
      path: "/groupcallManagement/task/index",
      name: "groupcallManagementTask",
      meta: {
        icon: "ri:chat-history-line",
        title: "外呼任务",
        roles: ["admin"]
      },
    },
    {
      path: "/groupcallManagement/statement/index",
      name: "groupcallManagementStatement",
      meta: {
        icon: "ri:file-list-2-line",
        title: "客户话单",
        roles: ["admin"]
      }
    },
    {
      path: "/groupcallManagement/reportForms/index",
      name: "groupcallManagementReportForms",
      meta: {
        icon: "ri:bar-chart-2-line",
        title: "统计报表",
        roles: ["admin"]
      }
    },
  ]
}

// 组织架构管理
const structureManagementRouter = {
  path: "/structureManagement",
  meta: {
    icon: "ri:building-2-line",
    title: "组织架构管理",
    rank: structure
  },
  children: [
    {
      path: "/structureManagement/dept/index",
      name: "structureManagementDept",
      meta: {
        icon: "ri:safe-2-line",
        title: "部门管理",
        roles: ["admin"]
      },
    },
    {
      path: "/structureManagement/position/index",
      name: "structureManagementPosition",
      meta: {
        icon: "ri:briefcase-2-line",
        title: "职位管理",
        roles: ["admin"]
      }
    },
    {
      path: "/structureManagement/role/index",
      name: "structureManagementRole",
      meta: {
        icon: "ri:group-line",
        title: "角色管理",
        roles: ["admin"]
      }
    },
    {
      path: "/structureManagement/account/index",
      name: "structureManagementAccount",
      meta: {
        icon: "ri:pass-pending-line",
        title: "成员管理",
        roles: ["admin"]
      }
    },
  ]
}

const systemManagementRouter = {
  path: "/system",
  meta: {
    icon: "ri:settings-3-line",
    title: "menus.pureSysManagement",
    rank: system
  },
  children: [
    {
      path: "/system/user/index",
      name: "SystemUser",
      meta: {
        icon: "ri:admin-line",
        title: "menus.pureUser",
        roles: ["admin"]
      }
    },
    {
      path: "/system/role/index",
      name: "SystemRole",
      meta: {
        icon: "ri:admin-fill",
        title: "menus.pureRole",
        roles: ["admin"]
      }
    },
    {
      path: "/system/menu/index",
      name: "SystemMenu",
      meta: {
        icon: "ep:menu",
        title: "menus.pureSystemMenu",
        roles: ["admin"]
      }
    },
    {
      path: "/system/dept/index",
      name: "SystemDept",
      meta: {
        icon: "ri:git-branch-line",
        title: "menus.pureDept",
        roles: ["admin"]
      }
    }
  ]
};

// 客户数据
const customerDataRouter = {
  path: "/customerData",
  meta: {
    icon: "ri:route-line",
    title: "客户数据",
    rank: customerData
  },
  children: [
    {
      path: "/customerData/index",
      name: "customerData",
      meta: {
        icon: "ri:repeat-2-line",
        showParent: true,
        title: "客户公海",
        roles: ["common"]
      },
    }
  ]
}

// 团队管理
const teamManagementRouter = {
  path: "/teamManagement",
  meta: {
    icon: "ri:group-line",
    title: "团队管理",
    rank: team
  },
  children: [
    {
      path: "/teamManagement/performance/index",
      name: "teamManagementPerformance",
      meta: {
        icon: "tabler:device-desktop-analytics",
        title: "成员业绩",
        roles: ["common"]
      },
    },
    {
      path: "/teamManagement/script/index",
      name: "teamManagementScript",
      meta: {
        icon: "tabler:message-2-search",
        title: "场景话术池",
        roles: ["common"]
      }
    }
  ]
}

// 群呼任务
const groupcallTaskRouter = {
  path: "/groupcallTask",
  meta: {
    icon: "ri:calculator-line",
    title: "群呼任务",
    rank: groupcallTask
  },
  children: [
    {
      path: "/groupcallTask/workbenches/index",
      name: "groupcallTaskWorkbenches",
      meta: {
        icon: "ri:mac-line",
        title: "工作台",
        roles: ["custom"]
      },
    },
    {
      path: "/groupcallTask/customerStatement/index",
      name: "groupcallTaskCustomerStatement",
      meta: {
        icon: "ri:file-list-2-line",
        title: "客户话单",
        roles: ["custom"]
      }
    }
  ]
}

// 话术资源
const scriptResourcesRouter = {
  path: "/scriptResources",
  meta: {
    icon: "ri:chat-poll-line",
    title: "话术资源",
    rank: script
  },
  children: [
    {
      path: "/scriptResources/index",
      name: "scriptResources",
      meta: {
        title: "话术资源",
        roles: ["custom"]
      },
    }
  ]
}

export default defineFakeRoute([
  {
    url: "/get-async-routes",
    method: "get",
    response: () => {
      return {
        success: true,
        data: [
          customerManagementRouter,
          productManagementRouter,
          groupcallManagementRouter,
          structureManagementRouter,
          // systemManagementRouter,

          customerDataRouter,
          teamManagementRouter,

          groupcallTaskRouter,
          scriptResourcesRouter
        ]
      };
    }
  }
]);
